/*author:hexinglong   2014.04.22 系统管理模块页面处理 */
var lineObj = document.getElementById('paidPoint');
var linexAxis = new Array();
var lineData = new Array();
var lineChart;


var barObj = document.getElementById('paidPerson');
var barxAxis = new Array();
var barData = new Array();
var barChart;


var dbbarObj = document.getElementById('paidMoneyPerson');
var dbbarxAxis = new Array();
var dbbarDatawa = new Array();
var dbbarDatahk = new Array();
var dbbarChart;

var pieObj = document.getElementById('paidPie');
var piexAxis = new Array();
var pieData = new Array();
var pieChart;

var Dashboard = {
    //初始化，放入页面加载时需要初始化的数据
    init: function (path) {
    	this.autoHeight();
        //按钮事件绑定
    	require.config({
    	    paths:{ 
    	        'echarts':path+'static/echarts/echarts',
    	        'echarts/chart/bar' : path+'static/echarts/map',
    	        'echarts/chart/line': path+'static/echarts/map',
    	        'echarts/chart/pie' : path+'static/echarts/map'
    	    }
    	});
    	require(
    		    [
    		        'echarts',
    		        'echarts/chart/bar',
    		        'echarts/chart/line',
    		        'echarts/chart/pie'
    		    ],
    		    Dashboard.print
    	);
    	 	
    },
    print:function(ec,t){
    	Dashboard.printCallback(ec);    	
    },
    printCallback:function(ec){
    	var option;
    	lineChart = ec.init(lineObj);
    	lineChart.showLoading({
    	    text: '正在努力的读取数据中...',    //loading话术
    	});
    	
    	barChart = ec.init(barObj);
    	barChart.showLoading({
    	    text: '正在努力的读取数据中...',    //loading话术
    	});
    	dbbarChart = ec.init(dbbarObj);
    	dbbarChart.showLoading({
    	    text: '正在努力的读取数据中...',    //loading话术
    	});
    	
    	pieChart = ec.init(pieObj);
    	pieChart.showLoading({
    	    text: '正在努力的读取数据中...',    //loading话术
    	});
    	
    	//显示加载进度条
    	$.ajax({
            url: "stat/statdashboard.do",
            dataType: "json",
            error: function (textStatus, errorThrown) {
                alert("系统ajax交互错误: " + textStatus);
            },
            success: function (data, textStatus) {
            	if(data.paidPoint){
            	for (var key in data.paidPoint)
                {
            		linexAxis.push(key);
            		lineData.push(data.paidPoint[key]);
                }
            	}
            	if(data.paidPerson){
            	for (var key in data.paidPerson)
                {
            		barxAxis.push(key);
            		barData.push(data.paidPerson[key]);
                }
            	}
            	if(data.paidMoneyPerson){
            	for (var key in data.paidMoneyPerson)
                {
            		dbbarxAxis.push(key);
            		dbbarDatahk.push(data.paidMoneyPerson[key].split(",")[0]);
            		dbbarDatawa.push(data.paidMoneyPerson[key].split(",")[1]);
                }
            	}
            	if(data.paidMoneyLim){
            	for (var key in data.paidMoneyLim)
                {
            		piexAxis.push(key);            		
            		pieData.push({value:data.paidMoneyLim[key],name:key});
                }
            	}
            	option = {
            		    title : {
            		        subtext: '百分比'
            		    },
            		    tooltip : {
            		        trigger: 'axis'
            		    },
            		    legend: {
            		        data:['回款率']
            		    },
            		    toolbox: {
            		        show : true,
            		        feature : {
            		            dataView : {show: true, readOnly: false},
            		            saveAsImage : {show: true}
            		        }
            		    },
            		    calculable : true,
            		    xAxis : [
            		        {
            		            type : 'category',
            		            boundaryGap : false,
            		            data :linexAxis
            		        }
            		    ],
            		    yAxis : [
            		        {
            		            type : 'value',
            		            axisLabel : {
            		                formatter: '{value} %'
            		            }
            		        }
            		    ],
            		    series : [
            		        {
            		        	tooltip:{
            		        		 formatter: '{b}回款率{c} %'
            		        	},
            		            name:'回款率',
            		            type:'line',
            		            data:lineData,
            		            markPoint : {
            		                data : [
            		                    {type : 'max', name: '最大值'},
            		                    {type : 'min', name: '最小值'}
            		                ]
            		            }
            		        }
            		    ]
            		};
            	 	try{
            		 lineChart.setOption(option);
            		}catch  (e)   {
            		   // alert(e.name  +   " :  "   +  e.message);
            		} 
                	
                	lineChart.hideLoading();
                	option = {
                    	    title : {
                    	        subtext: 'XXXXX'
                    	    },
                    	    tooltip : {
                    	        trigger: 'axis'
                    	    },
                    	    legend: {
                    	        data:['回款金额']
                    	    },
                    	    toolbox: {
                    	        show : true,
                    	        feature : {
                    	            dataView : {show: true, readOnly: true}
                    	        }
                    	    },
                    	    calculable : true,
                    	    xAxis : [
                    	        {
                    	            type : 'category',
                    	            data : barxAxis
                    	        }
                    	    ],
                    	    yAxis : [
                    	        {
                    	            type : 'value'
                    	        }
                    	    ],
                    	    series : [
                    	        {
                    	            name:'回款金额',
                    	            type:'bar',
                    	            data:barData,
                    	            markPoint : {
                    	                data : [
                    	                    {type : 'max', name: '最大值'},
                    	                    {type : 'min', name: '最小值'}
                    	                ]
                    	            },
                    	            markLine : {
                    	                data : [
                    	                    {type : 'average', name: '平均值'}
                    	                ]
                    	            }
                    	        }
                    	    ]
                    	};
                	try{
                		barChart.setOption(option);
               		}catch  (e)   {
               		   // alert(e.name  +   " :  "   +  e.message);
               		} 
                    	
                    	barChart.hideLoading();
                    	option = {
                        	    title : {
                        	        subtext: '单位（万元）'
                        	    },
                        	    tooltip : {
                        	        trigger: 'axis'
                        	    },
                        	    legend: {
                        	        data:['回款金额','委案金额']
                        	    },
                        	    toolbox: {
                        	        show : true,
                        	        feature : {
                        	            dataView : {show: true, readOnly: true}
                        	        }
                        	    },
                        	    calculable : true,
                        	    xAxis : [
                        	        {
                        	            type : 'category',
                        	            data : dbbarxAxis
                        	        }
                        	    ],
                        	    yAxis : [
                        	        {
                        	            type : 'value'
                        	        }
                        	    ],
                        	    series : [
                		        	        {
                		        	            name:'回款金额',
                		        	            type:'bar',
                		        	            data:dbbarDatahk,
                		        	            markPoint : {
                		        	                data : [
                		        	                    {type : 'max', name: '最大值'},
                		        	                    {type : 'min', name: '最小值'}
                		        	                ]
                		        	            },
                		        	            markLine : {
                		        	                data : [
                		        	                    {type : 'average', name: '平均值'}
                		        	                ]
                		        	            }
                		        	        },
                		        	        {
                		        	            name:'委案金额',
                		        	            type:'bar',
                		        	            data:dbbarDatawa,
                		        	            markPoint : {
                		        	                data : [
                		        	                    {type : 'max', name: '最大值'},
                		        	                    {type : 'min', name: '最小值'}
                		        	                ]
                		        	            },
                		        	            markLine : {
                		        	                data : [
                		        	                    {type : 'average', name: '平均值'}
                		        	                ]
                		        	            }
                		        	        }
                		        	    ]
                        	};
                    	try{
                    		dbbarChart.setOption(option);
                   		}catch  (e)   {
                   		   // alert(e.name  +   " :  "   +  e.message);
                   		} 
                    	
                    	dbbarChart.hideLoading();
                    	option = {
                    		    tooltip : {
                    		        trigger: 'item',
                    		        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    		    },
                    		    legend: {
                    		        orient : 'vertical',
                    		        x : 'left',
                    		        data:piexAxis
                    		    },
                    		    toolbox: {
                    		        show : true,
                    		        feature : {
                    		            dataView : {show: true, readOnly: false},
                    		            saveAsImage : {show: true}
                    		        }
                    		    },
                    		    calculable : true,
                    		    series : [
                    		        {
                    		            name:'回款组成',
                    		            type:'pie',
                    		            radius : '55%',
                    		            center: ['50%', '60%'],
                    		            data:pieData
                    		        }
                    		    ]
                    		};
                    	try{
                    		pieChart.setOption(option);
                   		}catch  (e)   {
                   		   // alert(e.name  +   " :  "   +  e.message);
                   		} 	                    
                    	
                    	pieChart.hideLoading();          	
            	
            }
    	});   
    },
    autoHeight:function(){
    	var footer = $("#foot").outerHeight();
    	var header = $("#head").outerHeight();
    	
    	var h = ($(window).height()-header-$("#s_menu_main").outerHeight()-footer)/2-50;
    	//var w = ($(window).width()-20)/2;
    	$(".i_div").css({height:h});
    }

};